package utils

import (
	"strconv"

	"github.com/astaxie/beego"
	"github.com/astaxie/beego/httplib"

	//"github.com/astaxie/beego/httplib"
)

type NewAddr struct {
	Addr string `json:"addr"`
}

type Response struct {
	Code int    // 0 正常，非0为具体错误码
	Msg  string //错误描述信息
	Data interface{}
}

func NewAddrPost(addr, coin string) Response {
	var error Response
	var url string
	if coin == "BTC" {
		url = beego.AppConfig.String("newbtcaddr_url")
	} else if coin == "LTC" {
		url = beego.AppConfig.String("newltcaddr_url")
	} else {
		error.Code = 1
		error.Msg = "币种不需要添加地址到全节点"
		return error
	}
	post := httplib.Post(url)
	body := NewAddr{
		Addr: addr,
	}
	post.JSONBody(body)
	resp, err := post.DoRequest()

	if err != nil {
		error.Code = 1
		error.Msg = "地址提交郭强热钱包错误" + err.Error()

	}
	if resp.StatusCode != 200 {
		error.Code = 1
		error.Msg = "地址提交郭强热钱包错误,返回值" + strconv.Itoa(resp.StatusCode)
	}
	return error

}
